package com.example.kx029;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.SystemClock;
import android.view.WindowManager;
import android.widget.Chronometer;

/**
 * 计时器
 */
public class MainActivity extends AppCompatActivity {

    Chronometer ch;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //设置页面全屏显示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        ch = findViewById(R.id.chronometer);
        //SystemClock.elapsedRealtime() 系统时间
        ch.setBase(SystemClock.elapsedRealtime());

        ch.setFormat("%s");

        ch.start();

        ch.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
            @Override
            public void onChronometerTick(Chronometer chronometer) {
                //60000 毫秒
                if (SystemClock.elapsedRealtime()-chronometer.getBase() > 60000){
                    ch.stop();
                }
                System.out.println(ch==chronometer);
            }
        });




    }
}